package summative;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuItem;


public class SaveListener implements ActionListener{

	VectorList list;
	JMenuItem item = new JMenuItem();
	JFileChooser jFileChooser = new JFileChooser();
	FileWriter writer;
	
	
	public SaveListener(JMenuItem item, VectorList list)
	{
		this.item = item;
		this.list = list;
	}
	
	public void setVectorList(VectorList list)
	{
		this.list = list;
	}
	
	public void actionPerformed(ActionEvent e) 
	{		
		try{
		
		jFileChooser.setSelectedFile(new File("*.txt"));	
		jFileChooser.showSaveDialog(null);
		
		writer = new FileWriter(jFileChooser.getSelectedFile());	
		
		BufferedWriter out = new BufferedWriter(writer);
		
		for(int x = 0; x<list.getArray().size(); x++)
		{
			out.write(list.getArray().get(x).getUnitVec());
			out.newLine();
		}
		
		
		out.close();
		}catch(Exception ex){
			
		}

	}
	
	

}
